package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.PackingListDao;
import cn.itcast.dao.cargo.InvoiceDao;
import cn.itcast.domain.cargo.Invoice;
import cn.itcast.domain.cargo.InvoiceExample;
import cn.itcast.domain.shipping.Shipping;
import cn.itcast.service.cargo.InvoiceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service(timeout = 3000)
public class InvoiceServiceImpl implements InvoiceService {

    @Autowired
    private InvoiceDao invoiceDao;

    @Autowired
    private PackingListDao packingListDao;
    /**
     * 分页查询
     * @param invoiceExample 分页查询的参数
     * @param pageNum         当前页
     * @param pageSize        页大小
     * @return
     */
    @Override
    public PageInfo<Invoice> findByPage(InvoiceExample invoiceExample, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Invoice> invoiceList = invoiceDao.selectByExample(invoiceExample);
        PageInfo<Invoice> pageInfo = new PageInfo<>(invoiceList);
        return pageInfo;
    }

    /**
     * 查询所有
     * @param invoiceExample
     */
    @Override
    public List<Invoice> findAll(InvoiceExample invoiceExample) {
        return invoiceDao.selectByExample(invoiceExample);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Invoice findById(String id) {
        return invoiceDao.selectByPrimaryKey(id);
    }

    /**
     * 新增
     * @param invoice
     */
    @Override
    public void save(Invoice invoice) {
        invoiceDao.insert(invoice);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public Integer delete(String id) {
        Invoice invoice = invoiceDao.selectByPrimaryKey(id);
        Integer status = Integer.valueOf(invoice.getStatus());
        if (status == 0) {
            int row = invoiceDao.deleteByPrimaryKey(id);
            return row;
        }else {
            return 0;
        }
    }
}
